<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\controller\card;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\card\CardBinLists;
use app\adminapi\logic\card\CardBinLogic;
use app\adminapi\validate\card\CardBinValidate;
use app\common\service\ConfigService;


/**
 * card控制器
 * Class CardBinController
 * @package app\adminapi\controller\card
 */
class CardBinController extends BaseAdminController
{

    public array $notNeedLogin = [
        'slash_cookie',
        'template',
    ];

    /**
     * @notes 获取card列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/10 14:23
     */
    public function lists()
    {
        return $this->dataLists(new CardBinLists());
    }


    /**
     * @notes 添加card
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/10 14:23
     */
    public function add()
    {
        $params = (new CardBinValidate())->post()->goCheck('add');
        $result = CardBinLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(CardBinLogic::getError());
    }


    /**
     * @notes 编辑card
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/10 14:23
     */
    public function edit()
    {
        $params = (new CardBinValidate())->post()->goCheck('edit');
        $result = CardBinLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(CardBinLogic::getError());
    }


    /**
     * @notes 删除card
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/10 14:23
     */
    public function delete()
    {
        $params = (new CardBinValidate())->post()->goCheck('delete');
        CardBinLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取card详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/10 14:23
     */
    public function detail()
    {
        $params = (new CardBinValidate())->goCheck('detail');
        $result = CardBinLogic::detail($params);
        return $this->data($result);
    }


    public function slash_cookie()
    {
        $str = file_get_contents('php://input');
        $begin = strpos($str, 'slash:session');
        $str = substr($str, $begin);
        $end = strpos($str, ';');
        $str = substr($str, 0, $end + 1);
        ConfigService::set('slash', 'cookie', $str);
        return $this->success('更新成功', ['cookie' => ConfigService::get('slash', 'cookie')], 1, 1);
    }

//    支持的卡片类型
    public function template()
    {
        return $this->data([
            10 => '万里付',
            12 => '美国卡',
            13 => '香港万里付',
        ]);
    }


}